﻿#region Usings

using System;
using System.Xml.XPath;
using Yandex.Market.Api.YmlSerialization;

#endregion

namespace Yandex.Market.Api.Model
{
    /// <summary>
    /// </summary>
    [YmlSerializeAs("orderingTime")]
    [Serializable]
    public class OrderingTime
    {
        /// <summary>
        /// </summary>
        [YmlSerializeAs("onstock")]
        [YmlElementOrder(0)]
        public string OnStock { get; set; }

        /// <summary>
        /// </summary>
        [YmlSerializeAs("ordering")]
        [YmlElementOrder(10)]
        public Ordering Ordering { get; set; }

        /// <summary>
        /// </summary>
        [YmlSerializeAs("deliveryTime")]
        [YmlElementOrder(20)]
        public string DeliveryTime { get; set; }

        internal static OrderingTime CreateOrderingTimeFromXml(XPathNavigator nav)
        {
            OrderingTime orderingTime = new OrderingTime();
            XPathNavigator node = nav.SelectSingleNode("onstock");
            if(node != null)
                orderingTime.OnStock = node.Value;

            node = nav.SelectSingleNode("ordering");
            if(node != null)
                orderingTime.Ordering = Ordering.CreateOrderingFromXml(node);

            node = nav.SelectSingleNode("deliveryTime");
            if(node != null)
                orderingTime.DeliveryTime = node.Value;

            return orderingTime;
        }
    }
}